#include<bits/stdc++.h>
#define ll long long
//#define rep(x,y,z) for(int x=(y);x<=(z);x++)
//#define per(x,y,z) for(int x=(y);x>=(z);x--)
//#define repn(x) rep(x,1,n)
//#define repm(x) rep(x,1,m)
using namespace std;
inline char gc()
{
	static char buf[1000000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int sum=0,f=0;
	char ch=gc();
	for(;!isdigit(ch);ch=gc())f|=(ch=='-');
	for(;isdigit(ch);ch=gc()) sum=((sum<<1)+(sum<<3)+(ch^48));
	return f?-sum:sum;
}
inline void write(int x)
{
    if(!x)
        putchar('0');
    char F[200];
    int tmp=x>0?x:-x;
    if(x<0)
        putchar('-');
    int cnt=0;
    while(tmp>0)
        F[cnt++]=tmp%10+'0',tmp/=10;
    while(cnt>0)
        putchar(F[--cnt]);
}

const int maxn=1e7+5,inf=(1LL<<31)-1,mod=1e9+7;
const ll llf=1e18;
inline void add(int &a,int b)
{
	((a+=b)>=mod) and (a-=mod);
}
inline int mul(int a,int b)
{
	return 1LL*a*b%mod;
}
int n,k,a[maxn],b[maxn],pw[maxn];
int q[maxn],h=1,t=1;
ll dp[maxn];
map<ll,int>alls;
inline void Insert(ll w)
{
    alls[w]++;
}
inline void Del(ll w)
{
    if(alls[w]==1)
		alls.erase(w);
    else 
		alls[w]--;
}
inline ll Min()
{
    if(alls.empty())
		return llf;
    return (*alls.begin()).first;
}
signed main()
{
	freopen("knight.in","r",stdin);
	freopen("knight.out","w",stdout);
	n=read();
	k=read();
	pw[0]=1;
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		pw[i]=mul(pw[i-1],23);
	}
	int ans=0,sum=0;
	dp[0]=0;
	q[1]=0;
	a[0]=inf;
	for(int i=1;i<=n;i++)
	{
        while(h<=t&&q[h]+k<i)
        {
        	Del(dp[q[h]]+a[q[h+1]]);
			h++;
		}
        while(h<=t&&a[i]>=a[q[t]])
		{
            if(h!=t)Del(dp[q[t-1]]+a[q[t]]);
            t--;
        }
        q[++t]=i;
        if(h<t)
			Insert(dp[q[t-1]]+a[i]);
        dp[i]=min(Min(),dp[max(0,i-k)]+a[q[h]]);
        add(ans,mul(dp[i]%mod,pw[n-i]));
	}
	cout<<ans;
	return 0;
}	
